class Solution(object):
    def findBuildings(self, heights):
        n = len(heights)
        out = [n - 1]
        max_val = heights[n - 1]
        for i in range(n - 2, -1, -1):
            if heights[i] > max_val:
                out.append(i)
            max_val = max(heights[i], max_val)
        out.reverse()
        return out